<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	var comboData = {
		equipmentType:null,
		deviceSupplier:null,
	}
	
	$(function() {

		$('#form').form({
			url : '/equipmentUserController/edit?bingType=2',
			onSubmit : function() {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var isValid = $(this).form('validate');
				if (!isValid) {
					parent.$.messager.progress('close');
				}
				return isValid;
			},
			success : function(result) {
				parent.$.messager.progress('close');
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_treeGrid这个对象，是因为resource.jsp页面预定义好了
					parent.$.modalDialog.handler.dialog('close');
				}else{
					parent.$.messager.alert('提示',result.msg,'info');
				}
			}
		});
		parent.$.messager.progress('close');
		
		
		//小区
		$.ajax({
			type:'post',
			url:'/deviceCommController/getShResidenceComboData',
			data:{},
			success:function(result) {
				comboData.residenceCombo = result.residenceCombo;
				$('#residenceId').combobox({
					data : comboData.residenceCombo,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto',
				    onSelect : function(a){
						var residenceId=a.value;
						getBuildingId(residenceId);//楼栋联动，得到小区的楼栋
					},
					value : '${deviceUser.residenceId}'
				});
			},
			dataType:'json'
		});
		
		//楼栋
		function getBuildingId(residenceId){
			$.ajax({
				type:'post',
				url:'/deviceCommController/getShBuildingComboData?residenceId=' +residenceId,
				data:{},
				success:function(result) {
					comboData.buildingCombo = result.buildingCombo;
					$('#buildingId').combobox({
						data : comboData.buildingCombo,
						valueField:'value',   
					    textField:'text',
					    panelHeight:'auto' ,
					    onSelect : function(a){
							var buildingId=a.value;
							getBuildingUnitId(buildingId);//单元联动，得到楼栋的单元
						} 
					});
				},
				dataType:'json'
			}); 
		}
		
		//单元
		function getBuildingUnitId(buildingId){
			$.ajax({
				type:'post',
				url:'/deviceCommController/getShBuildingUnitComboData?buildingId=' +buildingId,
				data:{},
				success:function(result) {
					comboData.buildingUnitCombo = result.buildingUnitCombo;
					$('#buildingUnitId').combobox({
						data : comboData.buildingUnitCombo,
						valueField:'value',   
					    textField:'text',
					    panelHeight:'auto',
					    onSelect : function(a){
							var buildingUnitId=a.value;
							getDoorId(buildingUnitId);//门牌联动，得到单元的门牌信息
						} 
					});
				},
				dataType:'json'
			});
		}
		
		
		//门牌
		function getDoorId(buildingUnitId){//根据单元id，得到门牌信息
			$.ajax({
				type:'post',
				url:'/deviceCommController/getShDoorComboData?buildingUnitId=' +buildingUnitId,
				data:{},
				success:function(result) {
					comboData.doorCombo = result.doorCombo;
					$('#doorId').combobox({
						data : comboData.doorCombo,
						valueField:'value',   
					    textField:'text',
					    panelHeight:'auto',
						//value : '${deviceUser.doorId}',
					    onSelect : function(a){
							var doorId=a.value;
							//getAccountId(doorId);//平台用户联动，得到所选门牌的用户信息
						}
					});
				},
				dataType:'json'
			});
		}
		
		//用户
		function getAccountId(doorId){//根据门牌id，得到用户信息
			$.ajax({
				type:'post',
				url:'/deviceCommController/getAccOuntComboData?doorId=' +doorId,
				data:{},
				success:function(result) {
					comboData.accountCombo = result.accountCombo;
					$('#platformUserId').combobox({
						data : comboData.accountCombo,
						valueField:'value',   
					    textField:'text',
					    panelHeight:'auto'
					});
				},
				dataType:'json'
			});
		}
		
		//设备基础信息
		$.ajax({
			type:'post',
			url:'/deviceCommController/getEquipmentInfoComboData',
			data:{},
			success:function(result) {
				comboData.equipmentInfoCombo = result.equipmentInfoCombo;
				$('#equipmentInfoId').combobox({
					data : comboData.equipmentInfoCombo,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto',
					value : '${deviceUser.equipmentInfoId}'
				});
			},
			dataType:'json'
		});
		
		//通信类型
		$.ajax({
			type:'post',
			url:'/deviceCommController/getDevCommTypeComboData',
			data:{},
			success:function(result) {
				comboData.equipmentCommTypeCombo = result.equipmentCommTypeCombo;
				$('#commType').combobox({
					data : comboData.equipmentCommTypeCombo,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto',
					onLoadSuccess: function(){
						$('#commType').combobox('setValue','${deviceUser.commType}');
					}
				});
			},
			dataType:'json'
		});
		
	});
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: auto;">
		<form id="form" method="post">
			<input type="hidden" name="id" value="${deviceUser.id }"/>
			<table class="table table-hover table-condensed">
			<tr>
					<th>小区id</th>
					<td ><input name="residenceId" id="residenceId" class="span2 " /></td>
					<th>楼栋id</th>
					<td ><input name="buildingId" id="buildingId" class="span2 " /></td>
				</tr>
				<tr>
					<th>单元id</th>
					<td ><input name="buildingUnitId" id="buildingUnitId" class="span2 " /></td>
					<th>门牌信息id</th>
					<td ><input name="doorId" id="doorId" class="span2 " /></td>
				</tr>
				<tr>
					
					<th>设备位置</th>
					<td ><input name="address" type="text" value="${deviceUser.address}" placeholder="请输入设备出厂编码" class="easyui-validatebox span2" data-options="required:true" ></td>
				</tr>
				<tr>
					<th>设备基础信息</th>
					<td colspan="3"><input name="equipmentInfoId" id="equipmentInfoId" class="span2 " /></td>
				</tr>
				<tr>
					<th>通信类型</th>
					<td ><input name="commType" id="commType" type="text" value="${deviceUser.commType}" placeholder="请输入设备出厂编码"  data-options="required:true" ></td>
					<th>通信状态</th>
					<td ><input type="radio" name="status" value="1">正常 &nbsp;<input type="radio" name="status"  value="2">冻结</td>
				</tr>
			</table>
		</form>
	</div>
</div>